package com.yzy.fly.boot.log;

import com.yzy.fly.api.annotation.ApiDoc;
import com.yzy.fly.api.annotation.ApiOperation;
import com.yzy.fly.api.annotation.RegisterFilterMapping;
import com.yzy.fly.api.function.response.entity.FlyApiResponseEntity;
import com.yzy.fly.api.function.response.entity.FlyTraceApiResponseEntity;
import com.yzy.fly.kernel.controller.FlyConstant;
import com.yzy.fly.kernel.controller.FlyCrudController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
//import static com.yzy.fly.kernel.controller.FlyConstant.PATH_SAVE;
import static com.yzy.fly.kernel.controller.FlyConstant.*;

@Slf4j
@ApiDoc(desc = "应用启动日志")
@RestController
@RequestMapping(value = "/app/log")
@RegisterFilterMapping(mappings = {PATH_ADD, PATH_SAVE, PATH_UPDATE, PATH_DELETE, PATH_UP, PATH_DOWN, PATH_QUERYTREE, PATH_LOADERBYID, PATH_QUERYLISTBYPARENTID})
public class FlyAppLogController extends FlyCrudController<Long, FlyAppLog> {

    @Autowired
    private FlyAppLogService flyAppLogService;

    @ApiOperation(value = "获取实体信息", notes = "根据ID获取对象信息", author = "yinzhiyuan")
    @GetMapping(value = PATH_QUERYBYID, produces = MediaType.APPLICATION_JSON_VALUE)
    public FlyApiResponseEntity queryById(@RequestParam Long id) {
        log.debug("id: " + id);
        long statTime = System.currentTimeMillis();
        FlyAppLog m = flyAppLogService.selectById(id);
        long endTime = System.currentTimeMillis();
        return FlyTraceApiResponseEntity.success("查询成功", m, (endTime - statTime));
    }

    @Override
    public String getType() {
        return FlyConstant.FLY_CORE;
    }
}

